package org.cocos2d.actions.instant;

import org.cocos2d.actions.CallFuncND;

/**
 * Calls a 'callback' with the node as the first argument and the 2nd argument is data ND means: Node Data
 */
public class CCCallFuncND extends CCCallFuncN {
	protected Object data;
	private CallFuncND callback;
	
	/** creates the action with the callback and the data to pass as an argument */
	public static CCCallFuncND action(Object t, String s, Object d) {
		return new CCCallFuncND(t, s, d, new Class<?>[] { Object.class, Object.class, });
	}
	
	/** creates the action with the callback and the data to pass as an argument */
	public static CCCallFuncND action(CallFuncND callback, Object d) {
		return new CCCallFuncND(callback, d);
	}
	
	/**
	 * creates the action with the callback and the data to pass as an argument
	 */
	protected CCCallFuncND(Object t, String s, Object d, Class<?>[] p) {
		super(t, s, p);
		data = d;
	}
	
	/**
	 * creates the action with the callback and the data to pass as an argument
	 */
	protected CCCallFuncND(CallFuncND callback, Object d) {
		super();
		this.callback = callback;
		data = d;
	}
	
	/**
	 * executes the callback
	 */
	public void execute() {
		if (callback != null) {
			callback.execute(target,data);
		} else {
			try {
				invocation.invoke(targetCallback, new Object[] { target, data });
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
